package com.gin.kotlin.no_gay_alliance.provider.ngaphp

import com.gin.nga.main.NgaApi
import com.gin.nga.response.user.SimpleUserInfo
import java.lang.ref.WeakReference

class PrivateMessageBlackListProvider private constructor():AbstractCachedDataProvider<Nothing,List<List<SimpleUserInfo>>,List<SimpleUserInfo>>(
    javaType = TYPE_FACTORY.constructCollectionLikeType(List::class.java, SimpleUserInfo::class.java),
) {
    override val dir = "PRIVATE_MESSAGE_BLACK_LIST"

    override fun transform(rawData: List<List<SimpleUserInfo>>) = rawData.flatten()

    override fun requestMethod(ngaApi: NgaApi, params: Nothing?) = ngaApi.messageApi.blockList()

    override fun obtainRelativePath(userId: Long, params: Nothing?) = "${userId}.json"

    companion object {
        private var instance: WeakReference<PrivateMessageBlackListProvider> = WeakReference(PrivateMessageBlackListProvider())
        fun getInstance(): PrivateMessageBlackListProvider = instance.get() ?: PrivateMessageBlackListProvider().also { instance = WeakReference(it) }
    }
}